home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pico / os2spell.c < prev    next >
C/C++ Source or Header  |  1996-05-22  |  3KB  |  126 lines

  1. #if    !defined(lint) && !defined(DOS)
  2. static char rcsid[] = "$Id: os2spell.c,v 4.4 1996/05/22 23:15:24 mikes Exp $";
  3. #endif
  4. /*
  5.  * Pine and Pico are registered trademarks of the University of Washington.
  6.  * No commercial use of these trademarks may be made without prior written
  7.  * permission of the University of Washington.
  8.  * 
  9.  * Pine, Pico, and Pilot software and its included text are Copyright
  10.  * 1989-1996 by the University of Washington.
  11.  * 
  12.  * The full text of our legal notices is contained in the file called
  13.  * CPYRIGHT, included with this distribution.
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include <process.h>
  18. #include "osdep.h"
  19. #include "estruct.h"
  20. #ifdef    SPELLER
  21. #include "pico.h"
  22. #include "edef.h"
  23.  
  24. /*
  25.  * spell - fork off an spell checker
  26.  * this is different for OS/2 with ispell; here, the document
  27.  * correction and interface is provided by ispell itself
  28.  */
  29. #define MAXARGS 10
  30. spell(f, n)
  31. {
  32.   char   sp[NLINE];                /* buf holding spell command */
  33.   char   *fn;                    /* tmp holder for file name */
  34.   char   *cp;
  35.   char   *args[MAXARGS];            /* ptrs into edit command */
  36.   char   *writetmp();
  37.   int    child, rc, i, done = 0;
  38.   long   l;
  39.   int    stat;
  40.   FILE   *p;
  41.  
  42.   if(Pmaster == NULL)
  43.     return(-1);
  44.  
  45.   if((fn = writetmp(0, 0)) == NULL){
  46.     emlwrite("Can't write temp file for spell checker");
  47.     return(-1);
  48.   }
  49.   if((cp = (char *)getenv("SPELL")) == NULL)
  50.     cp = SPELLER;
  51.   strcpy(sp,cp);
  52.  
  53.   if((fn=writetmp(0, 1)) == NULL){        /* get temp file */
  54.     emlwrite("Problem writing temp file for spell checker", NULL);
  55.     return(-1);
  56.   }
  57.  
  58.   strcat(sp, " ");
  59.   strcat(sp, fn);
  60.  
  61.   cp = sp;
  62.   for(i=0; *cp != '\0';i++) {            /* build args array */
  63.     if(i < MAXARGS) {
  64.       args[i] = NULL;            /* in case we break out */
  65.     }
  66.     else{
  67.       emlwrite("Too many args for command!", NULL);
  68.       return(-1);
  69.     }
  70.  
  71.     while(isspace((unsigned char)(*cp)))
  72.       if(*cp != '\0')
  73.     cp++;
  74.       else break;
  75.  
  76.     args[i] = cp;
  77.     while(!isspace((unsigned char)(*cp)))
  78.       if(*cp != '\0')
  79.     cp++;
  80.       else
  81.     break;
  82.  
  83.     if(*cp != '\0')
  84.       *cp++ = '\0';
  85.   }
  86.  
  87.   args[i] = NULL;
  88.  
  89.   (*Pmaster->raw_io)(0);            /* turn OFF raw mode */
  90.  
  91.   emlwrite("Invoking spell checker...", NULL);
  92.  
  93.   {
  94.     void (*ohup)() = signal(SIGHUP, SIG_IGN);    /* ignore signals for now */
  95.     void (*oint)() = signal(SIGINT, SIG_IGN);
  96.     cp=args[0];
  97.     rc = spawnvp(P_WAIT, cp, args);
  98.     signal(SIGHUP, ohup);    /* restore signals */
  99.     signal(SIGINT, oint);
  100.   }
  101.  
  102.   (*Pmaster->raw_io)(1);        /* turn ON raw mode */
  103.   dont_interrupt();
  104.  
  105.   if (rc==-1) {  /* Can't run it */
  106.       emlwrite("error attempting to run speller", NULL);
  107.   }
  108.   /*
  109.    * replace edited text with new text 
  110.    */
  111.   else{
  112.     rc = 0;
  113.     curbp->b_flag &= ~BFCHG;        /* make sure old text gets blasted */
  114.     readin(fn, 0);            /* read new text overwriting old */
  115.     curbp->b_flag |= BFCHG;        /* mark dirty for packbuf() */
  116.   }
  117.   unlink(fn);                /* blast temp file */
  118.  
  119.   ttopen();                /* reset the signals */
  120.   refresh(0, 1);            /* redraw */
  121.   return(rc);
  122. }
  123.  
  124. #endif    /* SPELLER */
  125.  
  126.